/*
 * @Date: 2025-06-13 14:10:52
 * @LastEditors: lyx
 * @LastEditTime: 2025-06-13 14:10:59
 * @FilePath: \blog\src\plugins\remark-excerpt.js
 * @Description: 自动生成摘要
 */
import { toString } from "mdast-util-to-string";

/* 使用文章的第一个段落作为摘要 */
export function remarkExcerpt() {
  return function (tree, { data }) {
    let excerpt = "";
    for (let node of tree.children) {
      if (node.type !== "paragraph") {
        continue;
      }
      excerpt = toString(node);
      break;
    }
    console.log('excerpt==>', excerpt);
    data.astro.frontmatter.excerpt = excerpt;
  };
}
